import { ApiProperty } from '@nestjs/swagger'
import { IsNumber, IsOptional, IsString, ValidateNested, ArrayMinSize, IsInt } from 'class-validator'
import { Type } from 'class-transformer'

export class CreateOrderItemDto {
  @ApiProperty({ description: '菜品ID' })
  @IsNumber()
  menu_id: number

  @ApiProperty({ description: '份数' })
  @IsNumber()
  quantity: number
}

export class CreateOrderDto {
  @ApiProperty({ description: '', required: false, default: '' })
  @IsOptional()
  order_id?: number

  @ApiProperty({ description: '用餐方式：1堂食 2外带' })
  @IsNumber()
  dining_method: number

  @ApiProperty({ description: '备注', required: false, default: '' })
  @IsOptional()
  @IsString()
  remark?: string

  @ApiProperty({ description: '订单状态：0待支付 1已支付 2已完成', required: false })
  @IsOptional()
  @IsNumber()
  status?: number

  @ApiProperty({
    description: '菜品列表',
    type: [CreateOrderItemDto],
  })
  @ValidateNested({ each: true })
  @Type(() => CreateOrderItemDto)
  @ArrayMinSize(1)
  items: CreateOrderItemDto[]

  @ApiProperty({ description: '订单总金额', readOnly: true })
  @IsOptional()
  @IsNumber()
  total_fee?: number
}